import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import { resolve } from 'path'

console.log(__dirname);
const root = process.cwd();
console.log(root);

function pathResolve(dir) {
  return resolve(root, '.', dir);
}

const pages = [
  {name: "index", htmlName: "index.html", htmlPath: "pages/index/"},
  {name: "about", htmlName: "index.html", htmlPath: "pages/about/"},
];

pages.forEach(page => {
  page.path = pathResolve(page.htmlPath + page.htmlName);
})

console.log(pages);

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
  ],
  build: {
      rollupOptions: {
          input: pages.reduce((res, cur) => {
              res[cur.name] = cur.path;
              return res;
          }, {}),
      },
      target: 'es2015'
  },
  server: {
    host: '0.0.0.0',
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
})
